<template>
	<view class="main">
		<image src="../../static/loginBG.png" class="main"></image>
		<view class="title">
			<uv-image src="/static/ROSUN.png" width="340rpx" height="42rpx" style="margin-bottom: 55rpx;"></uv-image>
			<view style="font-size: 16px;">欢迎，</view>
			<view style="font-size: 16px;">使用针车件资系统</view>
		</view>

		<view class="form">
			<h5>用户名</h5>
			<input v-model="user" placeholder="请输入您的用户名" />
			<view class="line"></view>

			<h5 class="password">密码</h5>
			<input v-model="password" placeholder="请输入您的密码" />
			<view class="line"></view>

			<h5 class="password">公司</h5>
			<input v-model="company" placeholder="请输入您的密码" />
			<view class="line"></view>

			<button @click="login">账号登录</button>
		</view>
		<uv-notify ref="notify" type="error"></uv-notify>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				user: JSON.parse(localStorage.getItem('user')) ? JSON.parse(localStorage.getItem('user')).name :
				'', //ZC201
				password: JSON.parse(localStorage.getItem('user')) ? JSON.parse(localStorage.getItem('user')).password :
					'', //byy256
				company: 'BF'
			};
		},
		methods: {
			login() {
				if (!this.user || !this.password || !this.company) {
					this.$refs.notify.show({
						message: '请输入用户名密码和公司'
					});
					return
				} else {
					uni.request({
						url: '/kl/pad/user/login',
						data: {
							"loginCompanyId": this.company,
							"loginName": this.user,
							"password": this.password
						},
						// header: {
						// 	'Authorization': '11_ZC201-token' //自定义请求头信息
						// },
						method: "POST",
						success: (res) => {
							console.log(res)
							if (res.data.code === 200) {
								uni.setStorage({
									key: 'token',
									data: res.data.data.Authorization,
								});
								uni.setStorage({
									key: 'userInfo',
									data: res.data.data.userInfo,
								});
								localStorage.setItem('user', JSON.stringify({
									name: this.user,
									password: this.password
								}))
								uni.reLaunch({
									url: '/pages/index/index'
								})
							} else {
								this.$refs.notify.show({
									message: res.data.message
								});
							}

						}
					});
				}
			}
		},
		onLoad() {

			console.log(11111111111111111, JSON.parse(localStorage.getItem('user')))
		}
	}
</script>


<style lang="less">
	.title {
		position: absolute;
		left: 20px;
		top: 60px;
		z-index: 999;

		h3 {
			line-height: 72rpx;
			font-size: 46rpx;
		}
	}

	.main {
		position: relative;
		width: 100vw;
		height: 100vh;
		background-size: cover;
		background-repeat: no-repeat;
	}

	.form {
		width: 90.5%;
		position: absolute;
		bottom: 0;
		z-index: 999;
		height: 60vh;
		border-radius: 60rpx 60rpx 0rpx 0rpx;
		padding: 50rpx 35rpx 0rpx;
		background: linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, #FFFFFF 100%);

		h5 {
			font-size: 35rpx;
		}

		input {
			margin-top: 20rpx;
			font-size: 26rpx;
		}

		.line {
			border: 2rpx solid #F5F5F5;
			width: 100%;
			margin-top: 30rpx;
		}

		.password {
			margin-top: 70rpx;
		}

		button {
			margin-top: 120rpx;
			color: white;
			background: linear-gradient(90deg, #2878FF 0%, #74BEFF 100%);
			border-radius: 46rpx 46rpx 46rpx 46rpx;
		}
	}
</style>